package ots.action;

import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

import ots.form.sendmessageForm;
import util.WriteXml;

public class sendmessageAction extends DispatchAction{
	public ActionForward execute(ActionMapping mapping,ActionForm form,HttpServletRequest request,
			HttpServletResponse response) throws Exception{
		sendmessageForm sendform = (sendmessageForm)form;
		try{
			String path =sendform.getPath();
			System.out.println(path);
			String message = sendform.getMessage();
			String title = sendform.getTitle();
			String sender = sendform.getSender();
			Date dt=new Date();
			SimpleDateFormat matter1=new SimpleDateFormat("yyyy-MM-dd");
			WriteXml.AppendChild(path, "Message", matter1.format(dt), title, message, sender);
			return mapping.findForward("success");
			
		}catch(Exception ex){
			return mapping.findForward("failure");
		}
	}

}
